package Client;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class upload extends JFrame implements ActionListener {

	private static final long serialVersionUID = 1L;

	JButton btn = null;

	JTextField textField = null;

	public upload() {
		this.setTitle("选择文件窗口");
		FlowLayout layout = new FlowLayout();
		JLabel label = new JLabel("请选择文件:");
		textField = new JTextField(30);
		btn = new JButton("浏览");

		JLabel xuehao = new JLabel("学号：:");
		JTextField ss = new JTextField(33);
		JButton upload = new JButton();
		upload.setText("上传");

		layout.setAlignment(FlowLayout.CENTER);
		this.setLayout(layout);
		this.setBounds(400, 200, 520, 100);
		this.setVisible(true);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		btn.addActionListener(this);
		this.add(label);
		this.add(textField);
		this.add(btn);

		this.add(xuehao);
		this.add(ss);

		this.add(upload);

		upload.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				String xuehao1 = ss.getText();
				ClientVariable.number = xuehao1;

				send qw;
				try {
					qw = new send();
					qw.good();
				} catch (Exception e) {
					e.printStackTrace();
				}

				DrawColumnHistogram ss = new DrawColumnHistogram();

				try {
					String str = ClientVariable.number;
					ss.shuzu(str);
					System.out.println("");
				} catch (SQLException e1) {
					e1.printStackTrace();
				}

			}
		});

	}

	public static void main(String[] args) {
		new upload();

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JFileChooser chooser = new JFileChooser();
		chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
		chooser.showDialog(new JLabel(), "选择");
		File file = chooser.getSelectedFile();

		ClientVariable.file = file.getAbsoluteFile().toString();
		String s = file.getAbsoluteFile().toString();

		String[] strarray = s.split("/");
		// String[] strarray = s.split(" /, \\, \");
		ClientVariable.filename = strarray[strarray.length - 1];
		textField.setText(file.getAbsoluteFile().toString());

	}

}